package com.yuezhu.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yuezhu.R;
import com.yuezhu.global.ApplicationContext;

/**
 * Created by 健 on 2016/5/20.
 */
public class MyProjectLeftAdapter extends BaseAdapter {

    private Context context;
    //侧滑菜单显示内容
    private String[] listDatas = new String[]{"电梯速算助手", "关于", "更多应用", "账户", "退出"};

    private int[] iconDatas = new int[]{R.drawable.helper, R.drawable.about, R.drawable.moreapp,
            R.drawable.account, R.drawable.quite2};

    public MyProjectLeftAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return listDatas.length;
    }

    @Override
    public Object getItem(int position) {
        return listDatas[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(ApplicationContext.getContext(), R.layout.item_myproject_listview, null);
            holder = new ViewHolder(convertView, position);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_title.setText(listDatas[position]);
        holder.iv_icon.setImageResource(iconDatas[position]);
        return convertView;
    }

    static class ViewHolder {
        ImageView iv_icon;
        TextView tv_title;
        ImageView iv_line;

        public ViewHolder(View convertView, int position) {
            iv_icon = (ImageView) convertView.findViewById(R.id.iv_item_icon);
            tv_title = (TextView) convertView.findViewById(R.id.tv_item_title);
            iv_line = (ImageView) convertView.findViewById(R.id.iv_line);
            if (position == 0) {
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) iv_icon.getLayoutParams();
                layoutParams.leftMargin = 10;
                iv_line.setVisibility(View.VISIBLE);
            }
        }
    }
}
